package com.ruoyi.web.controller.tongban;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tongban.domain.InsGrade;
import com.ruoyi.tongban.service.IInsGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 年级Controller
 * 
 * @author ruoyi
 * @date 2021-03-18
 */
@RestController
@RequestMapping("/tongban/grade")
public class InsGradeController extends BaseController
{
    @Autowired
    private IInsGradeService insGradeService;

    /**
     * 查询年级列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsGrade insGrade)
    {
        startPage();
        List<InsGrade> list = insGradeService.selectInsGradeList(insGrade);
        return getDataTable(list);
    }

    @GetMapping("/listInstitutionGrade")
    public AjaxResult listInstitutionGrade(@RequestParam Long id){
        List<InsGrade> list = insGradeService.listInstitutionGrade(id);
        return AjaxResult.success(list);
    }


    /**
     * 导出年级列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:grade:export')")
    @Log(title = "年级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InsGrade insGrade)
    {
        List<InsGrade> list = insGradeService.selectInsGradeList(insGrade);
        ExcelUtil<InsGrade> util = new ExcelUtil<InsGrade>(InsGrade.class);
        return util.exportExcel(list, "grade");
    }

    /**
     * 获取年级详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:grade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return AjaxResult.success(insGradeService.selectInsGradeById(gradeId));
    }

    /**
     * 新增年级
     */
    @PreAuthorize("@ss.hasPermi('tongban:grade:add')")
    @Log(title = "年级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsGrade insGrade)
    {
        return toAjax(insGradeService.insertInsGrade(insGrade));
    }

    /**
     * 修改年级
     */
    @PreAuthorize("@ss.hasPermi('tongban:grade:edit')")
    @Log(title = "年级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsGrade insGrade)
    {
        return toAjax(insGradeService.updateInsGrade(insGrade));
    }

    /**
     * 删除年级
     */
    @PreAuthorize("@ss.hasPermi('tongban:grade:remove')")
    @Log(title = "年级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeIds}")
    public AjaxResult remove(@PathVariable Long[] gradeIds)
    {
        return toAjax(insGradeService.deleteInsGradeByIds(gradeIds));
    }
}
